package com.chanzany.srb.sms.controller;

import com.chanzany.common.exception.Assert;
import com.chanzany.common.result.R;
import com.chanzany.common.result.ResponseEnum;
import com.chanzany.srb.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author ChanZany
 * @Date 2021/4/14 19:37
 * @Version 1.0
 */

@RestController
@RequestMapping("/api/sms")
@Api(tags = "短信管理")
@CrossOrigin //跨域
@Slf4j
public class ApiSmsController {

    @Resource
    private SmsService smsService;

    @ApiOperation("获取验证码")
    @GetMapping("/send/{mobile}")
    public R send(
            @ApiParam(value = "手机号", required = true)
            @PathVariable String mobile){
        Assert.notEmpty(mobile, ResponseEnum.MOBILE_NULL_ERROR);
        //发送短信
        smsService.send(mobile);
        return R.ok().message("短信发送成功");
    }
}
